package com.wh.wisdomsite.xbox.ba.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wh.wisdomsite.xbox.ba.dao.CommonDictMapper;
import com.wh.wisdomsite.xbox.ba.entity.CommonDict;
import com.wh.wisdomsite.xbox.ba.service.ICommonDictService;
import com.wh.wisdomsite.xbox.pojo.ba.CommonDictIn;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/***
 * 字典配置serviceImpl
 * @author 杨世强
 * @date 15:33 2018/8/2
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 * @version V1.0
 */
@Service("commonDictService")
@Transactional(rollbackFor = {Exception.class,RuntimeException.class})
public class CommonDictServiceImpl extends ServiceImpl<CommonDictMapper,CommonDict> implements ICommonDictService {

    private static final Log logger = LogFactory.getLog(CommonDictServiceImpl.class);

    @Autowired
    private CommonDictMapper commonDictMapper;

    @Override
    public boolean saveCommonDict(CommonDictIn commonDictIn) {
        CommonDict commonDict  = new CommonDict();
        //设置UUid 并且把-替换为"";
        commonDict.setCdId(UUID.randomUUID().toString().replace("-", ""));
        commonDict.setModelName(commonDictIn.getModelName());
        commonDict.setModelCode(commonDictIn.getModelCode());
        commonDict.setFunName(commonDictIn.getFunName());
        commonDict.setFunCode(commonDictIn.getFunCode());
        commonDict.setPropertyName(commonDictIn.getPropertyName());
        commonDict.setPropertyCode(commonDictIn.getPropertyCode());
        commonDict.setPropertySort(commonDictIn.getPropertySort());
        commonDict.setCreateDate(new Date());

        return commonDictMapper.insert(commonDict) > 0  ?  true : false;
    }

    @Override
    public List<CommonDict> getModelList() {
        return commonDictMapper.getModelList();
    }

    @Override
    public List<CommonDict> getFunList(String modelCode) {
        return commonDictMapper.getFunList(modelCode);
    }

    @Override
    public List<CommonDict> getPropertyList(String funCode) {
        return commonDictMapper.getPropertyList(funCode);
    }

}
